home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr49
/
118_01.zip
/
RAT2C.BDS
< prev
next >
Wrap
Text File
|
1993-06-03
|
4KB
|
229 lines
/* BDS C program to convert from RATFOR to C style comments
* source: rat2c.bds
* version: May 21, 1981.
*/
/* define globals */
#include bdscio.h
#define YES 1
#define NO 0
#define EOS 0
#define CR 13
#define LF 10
#define VERSION "ver: May 21, 1981"
#define SIGNON "Welcome to RAT4 to C comment converter. "
int input;
int output;
char buffer[100]; /* general buffer */
char inbuf[BUFSIZ]; /* input file buffer */
char outbuf[BUFSIZ]; /* output file buffer */
/* convert one file after another interactively */
main()
{
/* sign on */
puts(SIGNON);
puts(VERSION);
ccrlf();
/* mark files as closed */
input = -1;
output = -1;
while (1) {
if (openio() == NO) {
closeio();
break;
}
convert();
closeio();
}
puts("End of comment converter");
ccrlf();
}
/* open an input and output file.
* the input file must exist.
* the output file must not exist.
* return NO if the user gives up by entering a null file name.
*/
openio()
{
if (openin() == NO) {
return(NO);
}
else {
return(openout());
}
}
/* open the input file, which must exist.
* keep trying until the file is open or the user gives up.
*/
openin()
{
while (1) {
ccrlf();
puts("input file ? ");
gets(buffer);
if (buffer[0] == EOS) {
return(NO);
}
input = fopen (buffer,inbuf);
if (input == -1) {
ccrlf();
puts("file not found");
}
else {
return(YES);
}
}
}
/* open the output file, which must not exist.
* keep trying until the file is open or the user gives up.
*/
openout()
{
while (1) {
ccrlf();
puts("Output file ? ");
gets(buffer);
if (buffer[0] == EOS) {
return(NO);
}
/* make sure the file does not exist */
output = fopen(buffer,outbuf);
if (output != -1) {
ccrlf();
puts("File exists");
fclose(outbuf);
continue;
}
output = fcreat(buffer,outbuf);
if (output == -1) {
ccrlf();
puts("disk error");
}
else {
return(YES);
}
}
}
/* close any open files */
closeio()
{
if (input != -1) {
fclose(inbuf);
}
if (output != -1) {
fflush(outbuf);
fclose(outbuf);
}
}
/* copy input file to output file.
* convert everything following a '#' on a line into
* a C style comment.
*/
convert()
{
/* copy one line at a time */
while (do1line() == NO) {
;
}
}
/* copy one line from input file to output file.
* return YES if end of file has been seen.
*/
do1line()
{
int c; /* the current character */
int comflag; /* YES means in comment */
/* start off each line not in a comment */
comflag=NO;
while (1) {
/* get next character from input */
c = getc(inbuf);
if ( (c == -1) || (c == 0x1a) ) {
/* end of file */
if (comflag == YES) {
/* finish comment */
putc(' ',outbuf);
putc('*',outbuf);
putc('/',outbuf);
}
/* output end of file mark */
putc(0x01a,outbuf);
return(YES);
}
else if ((comflag == NO) &
(c == '#') ) {
/* start of comment */
comflag = YES;
putc('/',outbuf);
putc('*',outbuf);
putc(' ',outbuf);
}
else if (c == CR) {
/* end line. assume LF will follow */
c = getc(inbuf);
if (comflag == YES) {
/* finish comment */
putc(' ',outbuf);
putc('*',outbuf);
putc('/',outbuf);
}
/* finish line */
putc(CR,outbuf);
putc(LF,outbuf);
/* no EOF seen yet */
return(NO);
}
else {
/* just copy next character */
putc(c,outbuf);
}
}
}
/* output CR and LF to console */
ccrlf()
{
putchar(CR);
putchar(LF);
}
n a comment */
comflag=NO;if (c == CR) {
/* end line. assume LF will follow */
c = getc(inbuf);
if (comflag == YES) {
/* finish comment */
putc(' ',outbuf);
putc('*',outbuf);
putc('/',outbuf);
}
/* finish line */
putc(CR,outbuf);
putc(LF,outbuf);
/* no EOF seen yet */
return(NO);
}
else {
/* just copy next character */
putc(c,outbuf);